/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gruppe1projekt.ModelLayer;

import java.util.ArrayList;

public class ProductContainer
    {

    private static ProductContainer instance; //Singelton
    private ArrayList<Product> ProductList;

    private ProductContainer()
    {
        ProductList = new ArrayList<Product>();
    }

    // Her får den fat i instansen
    public static ProductContainer getInstance()
    {
        if (instance == null)
        {
            instance = new ProductContainer();

        }
        return instance;
    }

    public ArrayList<Product> getProductList()
    {
        return ProductList;
    }

    public void setProductList(ArrayList<Product> ProductList)
    {
        this.ProductList = ProductList;
    }

    // Finds a Product via Barcode
    public Product getProduct(long Barcode)
    {
        ArrayList<Product> PL = getProductList();
        for (Product P : PL)
        {
            if (P.getBarcode() == Barcode)
            {
                return P;
            }
        }
        return null;
    }

    //Add a product to list
    public void createProduct(Product P)
    {
        this.ProductList.add(P);
    }

    //Remove product from List
    public void deleteProduct(Product P)
    {
        this.ProductList.remove(P);
    }

    //Update product(Administrator + Employeee)
    public void updateProduct(Product P)
    {
        Product Pro = getProduct(P.getBarcode());
        Pro.setName(P.getName());
        Pro.setDescription(P.getDescription());
        Pro.setPurchasePrice(P.getPurchasePrice());
        Pro.setSubProduct(P.getSubProducts());
        Pro.setBarcode(P.getBarcode());
        Pro.setCount(P.getCount());
        Pro.setIsUnique(P.getIsUnique());
    }

    //Tilføj eksempel
    public void addCount(Product P, int number)
    {
        Product Pro = this.getProduct(P.getBarcode());
        Pro.addCount(number);

    }

    //Laver nyt serialnummer
    public void addProductItem(long Barcode, ProductItem PI)
    {
        Product Pro = getProduct(Barcode);
        Pro.addProductItem(PI);
    }

    public void addPrice(long Barcode, Price P)
    {
        Product Pro = getProduct(Barcode);
        Pro.addPrice(P);
    }

    //Henter listen ProductItems
    public ArrayList<ProductItem> getProductItems(long Barcode)
    {
        return getProduct(Barcode).getProductItems();
    }

    //Henter listen price
    public ArrayList<Price> getPrice(long Barcode)
    {
        return getProduct(Barcode).getPrices();
    }
    }
